package cn.rongdao.jrkabao.ui.information;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v4.content.ContextCompat;
import android.support.v4.util.ArrayMap;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chanven.lib.cptr.recyclerview.RecyclerAdapterWithHF;
import com.mifengkong.frwidget.titlebar.TitleBarUIComponent;

import java.lang.ref.WeakReference;
import java.util.Map;

import butterknife.BindView;
import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.base.FRBaseLooperRequestActivity;
import cn.rongdao.jrkabao.ui.loan.uicomponent.CommonHeaderUIComponent;

/**
 * Created by jiangyongxing on 2017/6/28.
 * 描述：
 */

public abstract class BaseApplyNeedInfoActivity extends FRBaseLooperRequestActivity {

    @BindView(R.id.annoi_desc_header)
    CommonHeaderUIComponent mCommonHeaderUIComponent;
    @BindView(R.id.aanoi_recyclerview)
    RecyclerView mAanoiRecyclerview;
    @BindView(R.id.aanoi_titlebar)
    TitleBarUIComponent mTitleBarUIComponent;

    final MyHandler myHandler = new MyHandler(this);
    protected Intent intent;

    protected Map<String, String> orderParmasMap = new ArrayMap<>();

    protected String mCateId = "";
    protected String mProductId = "";
    private RecyclerAdapterWithHF mRecyclerAdapterWithHF;


    @Override
    protected void initView() {
        super.initView();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);

        mRecyclerAdapterWithHF = new RecyclerAdapterWithHF(getAdapter());
        mAanoiRecyclerview.setLayoutManager(linearLayoutManager);
        mAanoiRecyclerview.setAdapter(mRecyclerAdapterWithHF);

        mCommonHeaderUIComponent.setContent("补充以下资料可提升额度");
    }

    protected abstract RecyclerView.Adapter getAdapter();

    protected void initTitleBar() {
        mTitleBarUIComponent.setBackgroundColor(ContextCompat.getColor(this, R.color.white));
        mTitleBarUIComponent.initLeftBackBlack(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTitleBarUIComponent.initRightHelpCenterBlack(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startHelpCenter();
            }
        });
    }



    @Override
    protected void onResume() {
        super.onResume();
        //请求数据
        myHandler.sendEmptyMessage(1);
    }

    @Override
    protected void baseLooperMethod() {
        super.baseLooperMethod();
        myHandler.sendEmptyMessage(1);
    }

    static class MyHandler extends Handler {

        WeakReference<BaseApplyNeedInfoActivity> mWeakReference;

        public MyHandler(BaseApplyNeedInfoActivity activity) {
            mWeakReference = new WeakReference<>(activity);
        }

        @Override
        public void handleMessage(Message msg) {
            BaseApplyNeedInfoActivity activity = mWeakReference.get();
            switch (msg.what) {
                case 1:
                    activity.requestData();
                    break;
            }
        }
    }

    protected abstract void requestData();

    @Override
    protected int layoutRes() {
        return R.layout.activity_apply_nedd_info;
    }

}
